package com.leinao.service;

import com.leinao.annotation.DataSource;
import com.leinao.domain.DeviceData;
import com.leinao.domain.TableInfo;
import com.leinao.domain.enums.DataSourceType;
import com.leinao.domain.param.DeviceDataQueryParam;
import com.leinao.mapper.TdengineMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * description
 *
 * @author zhong.wang
 * @date 2025/1/13
 */
@Service
@DataSource(DataSourceType.TDENGINE)
public class TdengingService {

    @Resource
    private TdengineMapper tdengineMapper;


    /**
     * 获取最后一次同步时间
     * @return
     */
    public Date getLastSyncTime(){
        return tdengineMapper.getLastSyncTime();
    }

    /**
     * 更新同步时间
     * @param ts
     */
    public void updateSyncTime(Date ts){
        tdengineMapper.updateSyncTime(ts);
    }

    /**
     * 根据超级表获取子表信息
     * @param tableName
     * @return
     */
    public List<TableInfo> getTableInfoBySuperTable(String tableName){
        return tdengineMapper.selectTableInfoBySuperTable(tableName);
    }

    /**
     * 插入数据
     * @param queryParam
     */
    public void insertData(DeviceDataQueryParam queryParam){
        tdengineMapper.insertData(queryParam);
    }

    /**
     * 创建表
     * @param tableName
     */
    public void createTable(String tableName) {
        tdengineMapper.createTable(tableName);
    }

    /**
     * 删除表
     * @param tableName
     */
    public void deleteTable(String tableName){
        tdengineMapper.deleteTable(tableName);
    }

    /**
     * 删除数据
     * @param queryParam
     */
    public void deleteDataByTs(DeviceDataQueryParam queryParam){
        tdengineMapper.deleteDataByTs(queryParam);
    }
    /**
     * 获取时间戳内所有数据
     * @param queryParam
     * @return
     */
    public List<DeviceData> getListByTs(DeviceDataQueryParam queryParam){
        return tdengineMapper.getListByTs(queryParam);
    }

    /**
     * 插入设局
     * @param deviceData
     */
    public void insertDeviceData(List<DeviceData> deviceData) {
        this.tdengineMapper.insertDeviceData(deviceData);
    }

    /**
     * 获取数据
     * @param queryParam
     * @return
     */
    public List<DeviceData> getDataAndAddDay(DeviceDataQueryParam queryParam){
        return this.tdengineMapper.getDataAndAddDay(queryParam);
    }
}
